package cn.sccl.mybatis.junt;

import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import cn.sccl.mybatis.mapper.OrderMapper;
import cn.sccl.mybatis.pojo.Orders;
import cn.sccl.mybatis.pojo.User;

/**
 * @author 饶爽
 * @time 2019年9月24日 下午11:32:40
 * @version 1.0.0
 * 订单相关业务测试类
*/
public class MybatisMapperTest2 {
    @Test
    public void testOrderList() throws Exception {
        //加载核心配置文件
        String resource = "sqlMapConfig.xml";
        InputStream in = Resources.getResourceAsStream(resource);
        //创建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
        //创建SqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();
        
        //SqlSEssion帮我生成一个实现类  （给接口）
        OrderMapper orderMapper = sqlSession.getMapper(OrderMapper.class);
        List<Orders> selectOrdersList = orderMapper.selectOrdersList();
        
        for (Orders orders : selectOrdersList) {
            System.out.println(orders);
        }
        sqlSession.close();
    }
    @Test
    public void testSelectOrders() throws Exception {
        //加载核心配置文件
        String resource = "sqlMapConfig.xml";
        InputStream in = Resources.getResourceAsStream(resource);
        //创建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
        //创建SqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();
        
        //SqlSEssion帮我生成一个实现类  （给接口）
        OrderMapper orderMapper = sqlSession.getMapper(OrderMapper.class);
        List<Orders> selectOrdersList = orderMapper.selectOrders();
        
        for (Orders orders : selectOrdersList) {
            System.out.println(orders);
        }
        sqlSession.close();
    }
    @Test
    public void testUserList() throws Exception {
        //加载核心配置文件
        String resource = "sqlMapConfig.xml";
        InputStream in = Resources.getResourceAsStream(resource);
        //创建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
        //创建SqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();
        
        //SqlSEssion帮我生成一个实现类  （给接口）
        OrderMapper orderMapper = sqlSession.getMapper(OrderMapper.class);
        List<User> users = orderMapper.selectUserList();
        for (User user : users) {
            System.out.println(user);
        }
    }
    
}
